package com.zte.cl.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import com.zte.cl.model.SeedPage;
import com.zte.cl.repository.SeedPageRepository;
import com.zte.cl.service.task.SeedPageTask;

@Service
public class SeedPageService {
	public final static Logger log = Logger.getLogger(SeedPageService.class);

	@Resource
	private SeedPageRepository seedPageRepository;
	
	@Resource(name = "seedPageThreadPool")
	private ThreadPoolTaskExecutor seedPageThreadPool;

	public void execute() {
		try {
			// 查找种子页面
			List<SeedPage> seedList = seedPageRepository.findByIsEnabledTrue();
			if (seedList != null) {
				log.info("t_seed_page发现 " + seedList.size() + " 个可用的种子Url");
				for (SeedPage seed : seedList) {
					seedPageThreadPool.execute(new SeedPageTask(seed));
				}
			} else {
				log.warn("t_seed_page 没有发现可用的数据.");
			}
		} catch (Exception e) {
			log.error("execute SendUrlService.execute()", e);
		}
	}
}
